import { Component, OnInit } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd';
import { OprationService } from 'src/app/service/opration.service';
import { WorkOrderService } from 'src/app/service/work-order.service';

@Component({
  selector: 'app-work-order',
  templateUrl: './work-order.component.html',
  styleUrls: ['./work-order.component.less']
})
export class WorkOrderComponent implements OnInit {

  datalist: any[] | null = null;
  isLoading: boolean = false;
  totalCount: number;
  selectData: any = {
    pagesize: 10,
    pageindex: 1
  }
  urgentText: string[] = ['', '一般', '紧急'];
  statusText: string[] = ['待处理', '已处理'];
  isDetailShow: boolean = false;
  data: any = {
    imageList: []
  };
  uploadUrl: string | null = '';
  headers: any | null = null;

  getlist() {
    this.isLoading = true;
    this.workOrderService.page(this.selectData).subscribe(result => {
      this.isLoading = false;
      this.totalCount = result['data']['count'];
      this.datalist = result['data']['items'];
    });
  }

  check(no: number) {
    this.data = this.datalist[no];
    if (this.data['images'] && this.data['images'] !== '') {
      let images: string[] = JSON.parse(this.data['images']);
      let uri: string = this.oprationService.ossUri;
      this.data['imageList'] = images.map(item => { return uri + item });
    }
    else {
      this.data['imageList'] = [];
    }
    this.isDetailShow = true;
  }

  close() {
    this.isDetailShow = false;
  }

  delete(id: number) {
    this.modalService.confirm({
      nzTitle: '信息提示',
      nzContent: '确定要删除此员工信息吗？',
      nzClosable: false,
      nzOnOk: () => {
        this.workOrderService.delete(id).subscribe(result => {
          this.oprationService.tips(result, '工单删除成功');
          if (result['code'] == 'success')
            this.getlist();
        });
      }
    });
  }

  constructor(
    private workOrderService: WorkOrderService,
    private modalService: NzModalService,
    private oprationService: OprationService
  ) { }

  ngOnInit(): void {
    this.getlist();
  }

}
